# Generated by Django 4.2.6 on 2025-11-13 14:18

from django.db import migrations
translation_mapping = {
    "de": [
        ("Veloreisender", "Veloreisende·r"),
        ("Velokurier", "Velokurier·in"),
        ("Mechaniker", "Mechaniker·in"),
        ("Polizist", "Polizist·in"),
        ("Stadtplaner", "Stadtplaner·in"),
    ],
    "fr": [
        ("Coursier/Livreur", "Coursier·ère/Livreur·euse"),
        ("Cyclovoyageur", "Cyclovoyageur·euse"),
        ("Mécanicien", "Mécanicien·ne"),
        ("Policier", "Policier·ère"),
        (" Autre", "Autre"), # Fix spacing
    ]
}



def apply_inclusive_updates(apps, schema_editor):
    Translation = apps.get_model("challenge", "QualificationActivityTranslation")

    for lang_code, pairs in translation_mapping.items():
        for old, new in pairs:
            Translation.objects.filter(
                language_code=lang_code,
                name=old
            ).update(name=new)
    refresh_cache()


def reverse_inclusive_updates(apps, schema_editor):
    Translation = apps.get_model("challenge", "QualificationActivityTranslation")

    for lang_code, pairs in translation_mapping.items():
        for old, new in pairs:
            Translation.objects.filter(
                language_code=lang_code,
                name=new
            ).update(name=old)
    refresh_cache()


def refresh_cache():
    from django.core.cache import cache
    cache.clear()


class Migration(migrations.Migration):

    dependencies = [
        ('challenge', '0086_inclusive_language'),
    ]

    operations = [
        migrations.RunPython(
            apply_inclusive_updates,
            reverse_inclusive_updates
        ),
    ]
